package com.lylg.picture_share.controller;

import com.lylg.picture_share.entity.Image;
import com.lylg.picture_share.entity.ImageType;
import com.lylg.picture_share.service.impl.ImageTypeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
@RequestMapping("/imagetype")
public class ImageTypeController {
    @Autowired
    private ImageTypeServiceImpl imageTypeService;


//    @RequestMapping("getall")
//    public List<ImageType> getAll(){
//        List<ImageType> imageTypes = imageTypeService.selectAllImageType();
//        System.out.println(imageTypes);
//        return imageTypes;
//    }
//    @RequestMapping("delete")
//    public Integer delete(ImageType imageType){
//        Integer integer = imageTypeService.deleteImageType(10);
//        return integer;
//    }
//    @RequestMapping("/update")
//    public Integer update(ImageType imageType){
//        imageType.setType_name("mv");
//        imageType.setType_id(9);
//        Integer integer = imageTypeService.updateImageType(imageType);
//        return integer;
//
//    }
//    @RequestMapping("/add")
//    public Integer add(ImageType imageType){
//        imageType.setType_name("dongwu");
//        Integer integer = imageTypeService.addImageType(imageType);
//        return integer;
//    }
//      @GetMapping("/toimagetype")
//      public String toLogin(){
//        return "/imagetype/imagetype";
//     }
    @GetMapping("/toadd")
    public String toAdd(){
        return "/manager/addimagetype";
    }

    @RequestMapping("/imagetypeui")
       public String getList( Model model){
        List<ImageType> imageTypes = imageTypeService.selectAllImageType();
        model.addAttribute("qb",imageTypes);
            return "/manager/imagetype";
        }
    @RequestMapping("/save")
    public String doSave( ImageType imageType){
          imageTypeService.addImageType(imageType);
        return "redirect:/imagetype/imagetypeui";
    }
//    @GetMapping("/del/{video_id}")
//    public String deleteVideo(@PathVariable("video_id") int id) {
//        videoService.deleteVideo(id);
//        return "redirect:/video/getallvideo";
//    }
    @GetMapping("/del/{type_id}")
    public String doDelete(@PathVariable("type_id") int id){
          imageTypeService.deleteImageType(id);
          return "redirect:/imagetype/imagetypeui";

    }
    @GetMapping("/toupdate/{type_id}")
    public String toUpdate(Model model,@PathVariable("type_id") Integer id){
        ImageType imageTypes = imageTypeService.selectImageTypeById(id);
        System.out.println(imageTypes);
        model.addAttribute("imagetypes",imageTypes);
        return "/manager/addimagetype";
    }
    @PostMapping("/update")
    public String update(Model model,ImageType imageType){
        System.out.println(imageType);
        imageTypeService.updateImageType(imageType);
        ImageType imageTypes = imageTypeService.selectImageTypeById(imageType.getType_id());
        model.addAttribute("imagetypes",imageTypes);
        return "redirect:/imagetype/imagetypeui";

    }

}
